#ifndef MEASURE_DATAPARSE_H
#define MEASURE_DATAPARSE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "vdsdef.h"
#include "measure_p.h"

#ifdef DEF_MEASURE_DATAPARSE_H
#define EXT_MEASURE_DATAPARSE
#else
#define EXT_MEASURE_DATAPARSE extern
#endif 


#define START_VALUE     0X0A0A0550 
#define CHECK_VALUE     0X09090606
#define STARTEND_VALUE  0X09060609 
#define CHECKEND_VALUE  0X05A0050A 
#define CHECKEMPTY_VALUE 0XFFFF

#define OFFSET_START            0   //同步开始
#define OFFSET_CHECK            4   //校验
#define OFFSET_DYNAMIC_CHECK    8   //动态校验
#define OFFSET_INFO_SIZE        10  //参数信息占用字节数
#define OFFSET_RUN_STATUS       12  //运行状态
#define OFFSET_ADC_PRECISION    14  //垂直分辨率
#define OFFSET_CH_NUMS          16  //数据中波形通道数
#define OFFSET_WAVE_DATA_SIZE   18  //每个通道波形数据点个数      
#define OFFSET_FRAME_NUMS       22  //波形叠加次数
#define OFFSET_FFT_VALID        24  //FFT数据有无
#define OFFSET_FFT_SIZE         26  //FFT原始数据点个数
#define OFFSET_DRAW_MODE        30  //画图模式,0:单点平铺,1:压缩画图,0xff:深存储数据
#define OFFSET_ROLL_MODE        32  //滚动模式,0：正常扫描,1:滚动模式
#define OFFSET_ROLL_DATA_SIZE   34  //滚动数据个数

#define OFFSET_FREQ_CH1         38
#define OFFSET_FREQ_CH2         42
#define OFFSET_FREQ_CH3         46
#define OFFSET_FREQ_CH4         50
#define OFFSET_REF_FREQ_CH1     54
#define OFFSET_REF_FREQ_CH2     58
#define OFFSET_REF_FREQ_CH3     62
#define OFFSET_REF_FREQ_CH4     66  

#define OFFSET_ADC_OVER_FLAG    70

#define OFFSET_ADC_MIN_CH1      72
#define OFFSET_ADC_MIN_CH2      74
#define OFFSET_ADC_MIN_CH3      76
#define OFFSET_ADC_MIN_CH4      78    
#define OFFSET_ADC_MAX_CH1      80
#define OFFSET_ADC_MAX_CH2      82
#define OFFSET_ADC_MAX_CH3      84
#define OFFSET_ADC_MAX_CH4      86
#define OFFSET_ADC_AVG_CH1      88
#define OFFSET_ADC_AVG_CH2      90
#define OFFSET_ADC_AVG_CH3      92
#define OFFSET_ADC_AVG_CH4      94    

#define OFFSET_TRIG_TYPE        96

#define OFFSET_VOLTSCALE_CH1    260
#define OFFSET_VOLTSCALE_CH2    262
#define OFFSET_VOLTSCALE_CH3    264
#define OFFSET_VOLTSCALE_CH4    266

#define OFFSET_ZERO_CH1         268
#define OFFSET_ZERO_CH2         272
#define OFFSET_ZERO_CH3         276
#define OFFSET_ZERO_CH4         280

#define OFFSET_TIMEPERDATA      548

    typedef struct {
        U32 start;
        U32 check;
        U16 dynamicCheck;
        U16 infoSize;
        U16 runStatus;
        U16 adcPrecision;
        U16 chNums;
        U32 waveDataSize;
        U16 frameNums;
        U16 fftValid;
        U32 fftDataSize;
        U16 drawMode;
        U16 rollMode;
        U32 rollDataSize;

        U32 voltScale[CH_TOTAL];
        S32 zero[CH_TOTAL];

        U32 freq[CH_TOTAL];
        U32 ref_freq[CH_TOTAL];

        U16 adcOverFlag;

        U32 adc_min[CH_TOTAL];
        U32 adc_max[CH_TOTAL];
        U32 adc_avg[CH_TOTAL];

        U16 trigType;

        F32 timePerData;

        U16 dynamicCheckEnd;
        U32 checkEnd;
        U32 startEnd;
    } ProtocolData;

    EXT_MEASURE_DATAPARSE ProtocolData protocolData;

    EXT_MEASURE_DATAPARSE BOOL measureDataParse(U8* data, U32 size, MeasureParam *measParam);
    EXT_MEASURE_DATAPARSE void measureDataDetach(U8* data, U32 size, MeasureParam *measParam);
    EXT_MEASURE_DATAPARSE void measureDataOneChannel(U8* data, U32 size, MeasureParam *measParam);
    EXT_MEASURE_DATAPARSE S32 getStepValue(S32 drawMode);
    EXT_MEASURE_DATAPARSE S32 getDynamicCheckEndOffset();
    EXT_MEASURE_DATAPARSE S32 getCheckEndOffset();
    EXT_MEASURE_DATAPARSE S32 getStartEndOffset();
    EXT_MEASURE_DATAPARSE U32 getU32Data(U8 *data, S32 offset);
    EXT_MEASURE_DATAPARSE U16 getU16Data(U8 *data, S32 offset);
    EXT_MEASURE_DATAPARSE F32 getF32Data(U8 *data, S32 offset);

#ifdef __cplusplus
}
#endif

#endif /* MEASURE_DATAPARSE_H */

